<template>
	<view class="container">
		<Header :isBack="true">
			<block slot="content">{{title}}</block>
		</Header>
		<view class="">
			<bjx-form class="form" :rules="rules" :form="formData" ref="form">
				<view class="realname">
					<bjx-form-item class="realname-user" label-type="inline" prop="salary" label="期望薪资">
						<input class="realname-content" type="text" value="" placeholder="请输入期望薪资(整数)"
							v-model="formData.salary" name="salary" />
					</bjx-form-item>
				</view>
				<view class="submit-box">
					<view class="submit" @tap="conSubmit">
						确定
					</view>
				</view>
			</bjx-form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '期望薪资',
				formData: {
					salary: ''
				},
				rules: {
					salary: {
						required: true,
						rule: 'type:number',
						message: {
							number: '薪资必须是整数'
						}
					}
				},
			};
		},
		onLoad(option) {
			//判断是否登录
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}

			this.formData.salary = option.salary;
		},
		methods: {

			conSubmit() {
				this.$refs.form.validate(val => {

					if (val == true) {
						let token = uni.getStorageSync('token');
						let dataObj = {
							token: token,
							salary: this.formData.salary
						};

						this.submit(dataObj);
					}
				})
			},

			//登录提交
			async submit(dataObj) {
				let res = await this.$myRequest({
					url: '/expectsalary',
					data: dataObj,
					methods: 'post'
				})
				if (res.data.status == 1) {
					this.$api.msg(res.data.msg, 1000);
					uni.$emit('changeSalary', {
						salary: this.formData.salary
					});
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages2/pages/work/work'
						})
					}, 1000)
				} else {
					this.$api.msg(res.data.msg);
				}
			}
		}
	}
</script>
<style>
	page {
		background-color: #f7f7f7;
		font-size: $font-base;
	}
</style>
<style lang='scss'>
	.container {
		// #ifdef APP-PLUS
		padding-top: 160rpx;
		// #endif
		
		// #ifdef H5
		padding-top: 100rpx;
		// #endif
	}

	.realname {
		line-height: 90rpx;
		height: 90rpx;
		background: #fff;
		padding: 0 48rpx;

		.realname-content {
			font-size: $font-base;
			color: #333;
		}
	}

	.submit-box {
		padding: 32rpx 48rpx;

		.submit {
			background-color: #f3431a;
			height: 60rpx;
			border-radius: 15rpx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}

	.realname {
		color: #808080 !important;
	}
</style>
